/**
 * <p>去掉新增删除按钮，去掉底下分页条。增加数据load回调函数，增加高度和宽度设定</p>
 * 
 * xtype = cceafcustomeditorgridpanel

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.CustomEditorGridPanel
 * @extends Ext.grid.GridPanel
 * @since 1.0
 */
Ext.define('cceaf.control.CustomEditorGridPanel',{
	extend: 'Ext.grid.GridPanel', 
    alias: 'widget.cceafcustomeditorgridpanel',

    requires: [
       'Ext.data.Store'
    ],
            
    /**
	 * 列表model
	 *
     * @property model 
     * @type String
     * @default null
     */
	model: null,
	/**  
	 * 数据加载回滚函数
	 * 
	 */
	loadcallback:null,
	/**
	 * 操作区的toolbar，在组装后的toolbar后追加
	 *
     * @property operateToolbar 
     * @type toolbar
     * @default null
     */
	operateToolbar: null,
	
	/**
	 * 操作区的toolbar
	 *
     * @property reOperateToolbar 
     * @type attribute toolbar
     * @default null
     */
	reOperateToolbar: null,
	
	constructor: function(config){
		config = config || {};
		
		var store;
		if (!config.model) {
			alert('请设置子表的model！');
		} else{
			store = new Ext.data.Store({model: config.model});
		}
		
		if(config.local == 'remote'){
			store = new Ext.data.Store({
		    	proxy: {
		    		type: 'ajax',
		    		url:  config.queryAction,
		    		actionMethods: {  
			            read: 'POST'  
			        },  
		    		reader: {
						type: 'json',
						root: 'data',
						totalProperty: 'totalCount',
						messageProperty: 'message'
					}
				},
				
		        listeners: {
		        	'load': function(ds,r){
		        		var jr = ds.getProxy().getReader();
		        		if(!jr.jsonData) {
		        			cceaf.util.ExtHelper.showErrorDialog("没有设置正确的action或没有返回正确的json字符串！");
		        			return;
		        		}
		        		
		        		var message = jr.jsonData.message;
		        		var url = jr.jsonData.url;
		        		cceaf.util.ExtHelper.showInfoDialog(message,url);
		        		if(config.loadcallback){
		        			config.loadcallback(ds,r,config.id);
		        		}
		        	},
		        	'loadexception': function(ds){
		        		var jr = ds.getProxy().getReader();
		        		if(jr.jsonData){
			        		var message = jr.jsonData.message;
			        		var url = jr.jsonData.url;
			        		cceaf.util.ExtHelper.showErrorDialog(message,url);
		        		}
		        		else{
		        			cceaf.util.ExtHelper.showErrorDialog("返回无效的JSONDATA数据");
		        		}
		        	}
		        	
		        },
		        groupField: config.groupField,
		        autoDestroy: true,  
		        autoLoad:true,
		    	pageSize: szpshang.Global.PAGE_SIZE,
		    	model: config.model
		    });
		}
		
		var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
			pluginId: 'pluginIdOfcceafDetaileditorgridpanel',
            clicksToEdit: 1
        });
		
		
		var height = config.height;
		var width = config.width;
		if(config.height == null){
			height = cceaf.util.ExtHelper.getMainContentHeight();
		}
		if(config.width == null){
			width = cceaf.util.ExtHelper.getMainContentWidth();
		}
		Ext.applyIf(config || {}, {
			store: store,
	        border: true,
	        frame: config.local != 'remote',
	        flex: 1,
	        selType: 'cellmodel', // 选择类型设置为：单元格选择 
	        plugins: [cellEditing],
	        loadMask: {msg:'正在加载数据，请稍侯……'}
		});
		
		if(!config.autoWidth){
			Ext.applyIf(this, {
		        width: width
			});
		}
		if(!config.autoHeight){
			Ext.applyIf(this, {
		        height: height
			});
		}

		cceaf.control.CustomEditorGridPanel.superclass.constructor.apply(this, arguments);
	},
	
	viewConfig: {
		forceFit:true,
		enableRowBody:true,
		getRowClass : function(record, rowIndex, p, ds){
			return '';
		}
	},
	
	initComponent : function(){
		cceaf.control.CustomEditorGridPanel.superclass.initComponent.call(this);
    },

    initEvents: function() {
    	cceaf.control.CustomEditorGridPanel.superclass.initEvents.call(this);
    },
    
    /**
     * 在点击增加行时执行,父类不执行,可在子类重载
     */
    initAddRow: function(){
    	
    }
    
});